package com.gitee.wsl.mathematics.matrix.mat2

import com.gitee.wsl.ext.array.DoubleArray
import com.gitee.wsl.io.dataproxy.DataProxy
import com.gitee.wsl.io.dataproxy.asProxy
import com.gitee.wsl.mathematics.matrix.M
import com.gitee.wsl.mathematics.matrix.MatCopyInitializer
import com.gitee.wsl.mathematics.matrix.N
import com.gitee.wsl.mathematics.vector.vec2.MutableVec2
import com.gitee.wsl.mathematics.vector.vec2.Vec2

class MutableMat2( m00: Double=0.0, m01: Double=0.0,
                   m10: Double=0.0, m11: Double=0.0,
                   override val proxy: DataProxy<Double> = DoubleArray(m00, m01,m10, m11).asProxy())
    :Mat2(proxy = proxy),MutableMatrix2D<Mat2, Vec2> {
    constructor(other:Matrix2D<*,*>):this(other.m00,other. m01, other.m10, other.m11)

    override val self
        get() = this

    override val m by lazy{listOf(M[0], M[1])}

    override val n by lazy {listOf(N[0], N[1])}

    override fun copy(block: MatCopyInitializer<Double>) = MutableMat2(
        m00.block(0,0),
        m01.block(0,1),
        m10.block(1,0),
        m11.block(1,1))

    //override fun createVec(indexRage:IntRange) = createVec(indexRage.toList())

    override fun createVec(indexes: List<Int>) = MutableVec2(proxy = proxy.asProxy(indexes))

    override fun create(m00: Double, m01: Double, m10: Double, m11: Double) = MutableMat2(m00, m01, m10, m11)

    override operator fun M.get(row: Int) = createVec(rowIndexes(row))

    override operator fun N.get(col: Int) = createVec(colIndexes(col))

    companion object{
        val IDENTITY  = identity()

        fun identity()= MutableMat2(
            1.0, 0.0, 
            0.0, 1.0
        )
    }

}